package com.cindata

import com.cindata.dictionary.*

class AbnormalMortgageBatch
{

    String name
    String disposeMethod
    //处置方式：债券转让、所有权转让
    Workflow workflow

    AbnormalMortgageBatchStage stage
    String status = "Pending"
    String descriptionOfFailure
    //失败原因说明

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User user
    User createBy
    User modifyBy

    Date startTime
    Date endTime

    Date actualStartTime
    Date actualEndTime

    Department disposalDepartment
    User disposalUser
    String description

    Boolean isInitWorkFlow = false

    static hasMany = [mortgages: BatchMortgage]

    static constraints = {
        disposeMethod inList: ['债权转让', '所有权转让']

        stage nullable: true, blank: true
        status nullable: true, blank: true
        status inList: ["Pending", "Failed", "Completed"]
        workflow nullable: true, blank: true

        descriptionOfFailure nullable: true, blank: true

        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        user nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true

        startTime nullable: true, blank: true
        endTime nullable: true, blank: true
        actualStartTime nullable: true, blank: true
        actualEndTime nullable: true, blank: true

        disposalDepartment nullable: true, blank: true
        disposalUser nullable: true, blank: true
        description maxSize: 512, nullable: true, blank: true
        isInitWorkFlow nullable: true, blank: true

    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        def user = User.findByUsername(username)
        createBy = user
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }

}
